/**
 * 
 */
package vanhoc.android.mediakool;

import vanhoc.android.mediakool.R;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.MediaController;
import android.widget.VideoView;

/**
 * @author Administrator
 *
 */
public class VideoPlayerActivity extends Activity implements OnCompletionListener, OnPreparedListener {
	VideoView videoView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.video_player);
		
		videoView	=	(VideoView) findViewById(R.id.videoView);
		
		//get Intent
		String videoPath = getIntent().getExtras().getString("VIDEOPATH");
		
		
		videoView.setOnPreparedListener(this);
		videoView.setOnCompletionListener(this);
		videoView.setKeepScreenOn(false);
		
		videoView.setVideoPath(videoPath);
		
		videoView.setMediaController(new MediaController(this));
		videoView.start();
	}

	@Override
	public void onPrepared(MediaPlayer mp) {
		// Don't start until ready to play.  The arg of seekTo(arg) is the start point in
        // milliseconds from the beginning. In this example we start playing 1/5 of
        // the way through the video if the player can do forward seeks on the video.
		/*if(videoView.canSeekForward()) videoView.seekTo(videoView.getDuration()/5);
		videoView.start();*/
	}

	
	/** This callback will be invoked when the file is finished playing */
	@Override
	public void onCompletion(MediaPlayer mp) {
		//this.finish();
	}
	
	
	 /**  Use screen touches to toggle the video between playing and paused. */
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		return super.onTouchEvent(event);
		/*if (event.getAction()	==	MotionEvent.ACTION_DOWN) {
			if (videoView.isPlaying()) {
				videoView.pause();
			}else{
				videoView.start();
			}
			return true;
		}else{
			return false;
		}*/
	}
}
